/**
 * Created by Void on 2017/9/27.
 */

import {Component, ViewChild} from '@angular/core';
import {ViewController,NavController, Searchbar} from 'ionic-angular'

import {HttpService} from '../../../providers/HttpService';
import {NativeServiceC} from "../../../providers/NativeServiceC";
import {GlobalData} from "../../../providers/GlobalData";
import {get} from "@ionic-native/core";

@Component({
    selector: 'page-searchShop',
    templateUrl: 'searchShop.html'
})
export class SearchShopPage{

    private searchBarText:string = '';
    private showSearchBar:boolean = true;
    private inputing:boolean = true;

    private nextShopUrl:string = '';
    private nextCollectionUrl:string = '';
    private orderType:string = '';
    private segmentValue:string = 'shop';
    @ViewChild('searchBar') private searchBar:Searchbar;
    constructor(
        public navCtrl:NavController,
        private viewCtrl:ViewController,
        private httpService:HttpService,
        private nativeService:NativeServiceC,
        private globalData:GlobalData
    ) {
    }
    ionViewDidLoad() {
        // this.viewCtrl.showBackButton(false);
    }
    ionViewDidEnter(){
    }
    ionViewWillLeave(){
        this.showSearchBar = false;
    }
    ionViewDidLeave(){
    }

    searchInputFocus(){
        this.inputing = true;
    }
    shopOrderby(){
        console.log('排序');
    }
    searchInputBlur(){
        setTimeout(()=>{
            this.inputing = false;
        },0)
    }

    searchClick(){
        this.searchBarText = this.searchBarText.trim();
        if (this.searchBarText.length === 0) return;

        const shopUrl = `/v1/search/item?keyword=${this.searchBarText}&limit=20&offset=0&sort=${this.orderType}`;
        const collectionUrl = `/v2/search/post?keyword=${this.searchBarText}&limit=20&offset=0&sort=${this.orderType}`;
        this.getShops(shopUrl);
        this.getCollection(collectionUrl);


    }

    getShops(url:string){

        this.httpService.get(url)
            .subscribe(res => {
                this.nativeService.hideLoading();
                console.log(res);
            })
    }
    getCollection(url:string){
        this.httpService.get(url)
            .subscribe(res => {
                this.nativeService.hideLoading();
                console.log(res);
            })
    }


}